/**
 * @Author: LiMeng
 * @Date: 2017/3/16
 */
$(function () {
    var duties = $(':input[name=duties]').val();//用户职位
    var id = $(':input[name=id]').val();//用户名
    initUseSate();
    initGender();
    initEducation();
    initMaritalStatus();
    initUserTitle();
    initAdministrativeLevel();
    initWorkBigType();
    initMajorBigType();
    initPost();

    //职位下拉框
    $('#duty').combotree({
        url: ROOT_PATH + '/permission/department/getDeptAndDutyTreeByUserId.shtml?userId=' + id,
        multiple: true,
        editable: false,
        onlyLeafCheck: true,
        valueField: 'id',
        textField: 'text',
        value: duties
    });

    $('#btn_save').on("click", function () {
        $.messager.progress();	// 显示进度条
        $('#form_user').form('submit', {
            url: ROOT_PATH + '/permission/user/edit.shtml',
            onSubmit: function (param) {
                if ($(':input[name=dutyId]').length === 0) {
                    param.dutyId = '';
                }
                var isValid = $(this).form('validate');
                if (!isValid) {
                    $.messager.progress('close');	// 如果表单是无效的则隐藏进度条
                }
                return isValid;	// 返回false终止表单提交
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success) {
                    $.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message, {time: 1000, icon: 1}, function () {
                        parent.$('#dg1').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                } else {
                    $.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message, {time: 1000, icon: 2});
                }
            }
        });
    });
    $('#btn_clear').on("click", function () {
        $('#form_user').form('reset');
    });
});